package logic

import (
	"context"
	"post/docker/mysql"

	"post/postrpc/internal/svc"
	"post/postrpc/postrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RecordHotListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRecordHotListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RecordHotListLogic {
	return &RecordHotListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RecordHotListLogic) RecordHotList(in *postrpc.RecordHotListRequest) (*postrpc.RecordHotListResponse, error) {
	// todo: add your logic here and delete this line
	var record []mysql.Record

	mysql.DB.Debug().Limit(10).Order("create_at desc").Find(&record)
	var recordHotList []*postrpc.RecordList
	for _, m := range record {
		list := postrpc.RecordList{
			Id:         int64(m.ID),
			UserId:     m.UserId,
			Comment:    m.Comment,
			Title:      m.Title,
			ActivityId: m.ActivityId,
			ClassId:    m.ClassId,
		}
		recordHotList = append(recordHotList, &list)
	}
	return &postrpc.RecordHotListResponse{}, nil

}
